import api from './index'

// 认证相关API
export const authAPI = {
  // 管理员登录
  adminLogin: (credentials) => {
    const loginData = {
      username: credentials.username,
      password: credentials.password,
      role: 0, // 0是admin
      userId: 0
    }
    return api.post('user/login', loginData)
  },

  // 学生登录
  studentLogin: (credentials) => {
    const loginData = {
      username: credentials.username || credentials.studentId,
      password: credentials.password,
      role: 1, // 1是student
      userId: 0
    }
    return api.post('user/login', loginData)
  },

  // 登出
  logout: () => {
    return api.post('/auth/logout')
  },

  // 刷新token
  refreshToken: () => {
    return api.post('/auth/refresh')
  },

  // 修改密码
  changePassword: (data) => {
    return api.post('/auth/change-password', data)
  },

  // 获取用户信息
  getUserInfo: () => {
    return api.get('/auth/user-info')
  }
}